package com.sun.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hugh.sun
 * @date 2021/11/14 13:51
 */
@Api
@RestController
public class RedisController {
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/redis/get/{key}")
    public Object getRedis(@PathVariable String key){
        /*根据key去获取value*/
        Object o = redisTemplate.opsForValue().get(key);
        return o;
    }
    @PostMapping("/redis/set/{key}/{value}")
    public Object set(@PathVariable String key, @PathVariable String value){
        /*设置key和value String类型*/
        redisTemplate.opsForValue().set(key,value);
        return "set success";
    };



}
